package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;

/** 版本订购年限 */
public class VersionOrderingYearsAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

  @Autowired OperateInstAttrService operateInstAttrService;

  @Resource private IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
    super.after(attr, inst, data);

    List<KiteProdInst> kiteProdInstList = querySceneInstService.listProdInsts(data.getSceneInstId());
    // 主产品的版本订购年限
    String attrValue = kiteProdInstList.stream()
            .filter(prodinst -> "63249688".equals(prodinst.getSpecId()))
            .collect(Collectors.toList())
            .get(0)
            .getAttrValue("210008135");
    operateInstAttrService.setAttrValue(inst, "210008136", attrValue, data.getSceneInstId(), null);
  }
}
